package com.yeskery.nut.extend.responsive;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * 类型引用接口
 * @author sprout
 * 2025-04-17 15:40
 */
public abstract class TypeReference<T> {

    /** 反射类型 */
    protected final Type type;

    /**
     * 获取反省类型
     * @return 反省
     */
    public Type getType() {
        return type;
    }

    /**
     * 通过构造器获取泛型类型
     */
    protected TypeReference() {
        Type superClass = this.getClass().getGenericSuperclass();
        if (superClass instanceof Class) {
            throw new IllegalArgumentException("Generic Type Was Not Obtained.");
        } else {
            this.type = ((ParameterizedType)superClass).getActualTypeArguments()[0];
        }
    }
}
